package manual.tema3.dataBases;
    import java.sql.*;

     

    public class ProvaMySql {

     

            public static void main(String[] args)

            {

                   Connection connect = null;

                   Statement statement = null;

                   ResultSet resultSet = null;

                  

                   try {

                           // This will load the MySQL driver

                  

                          // Class.forName("com.mysql.jdbc.Driver");

                          

                                  // Setup the connection with the DB

                        //   connect = DriverManager.getConnection("jdbc:mysql://localhost/Java_a_fondo", "root", "");

                           

                           // Statements allow to issue SQL queries to the database
                	   
                	   		connect = UConnection.getCon();

                           statement = connect.createStatement();

                          

                         //creamos la base de datos e introducimos algunos datos

                           statement.execute("create database ejemplo;");

                           statement.execute("use ejemplo");

                           statement.execute("create table clientes (id INT not null, nombre VARCHAR (10), primary key (id));");

                           statement.execute("insert into clientes values (3, 'Juan');");

                           statement.execute("insert into clientes values (4, 'Maria');");

                           statement.execute("insert into clientes values (5, 'Pedro');");

                  

                           // Result set get the result of the SQL query

                           resultSet = statement.executeQuery("select * from clientes");

                          

                           //Ahora procesamos el resultado

                           System.out.println("Contenido de la base de datos");

                           while (resultSet.next())

                  {  

                                   String nombre = resultSet.getString("nombre");

                                   int id = resultSet.getInt("id");

                                  

                                   System.out.println("Nombre: " + nombre + " Identificador: " + id);

                                  

                           }

                           statement.close();

                        //   connect.close();

                          

                   } catch (Exception e)

                   {

                           System.out.println ("Error base de datos");

                   }

            }

     }
